/*
 * $Id: Constants.java 471756 2006-11-06 15:01:43Z husted $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package trans.support;

import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

/**
 * <p> Manifest constants for the MailReader application. </p>
 */
public final class Constants {

    // --- Tokens ----

    /**
     * <p> The token representing a "cancel" request. </p>
     */
    public static final String CANCEL = "cancel";

    /**
     * <p> The token representing a "create" task. </p>
     */
    public static final String CREATE = "Create";

    /**
     * <p> The application scope attribute under which our user database is
     * stored. </p>
     */
    public static final String DATABASE_KEY = "database";

    /**
     * <p> The token representing a "edit" task. </p>
     */
    public static final String DELETE = "Delete";

    /**
     * <p> The token representing a "edit" task. </p>
     */
    public static final String EDIT = "Edit";

    /**
     * <p> The package name for this application. </p>
     */
    public static final String PACKAGE = "org.apache.struts.apps.mailreader";

    /**
     * <p> The session scope attribute under which the Subscription object
     * currently selected by our logged-in User is stored. </p>
     */
    public static final String SUBSCRIPTION_KEY = "subscription";

    /**
     * <p> The session scope attribute under which the User object for the
     * currently logged in user is stored. </p>
     */
    public static final String USER_KEY = "user";

    /**
     * <p>The token representing the "Host" property.
     */
    public static final String HOST = "host";


    // ---- Error Messages ----

    /**
     * <p>
     * A static message in case message resource is not loaded.
     * </p>
     */
    public static final String ERROR_MESSAGES_NOT_LOADED =
            "ERROR:  Message resources not loaded -- check servlet container logs for error messages.";

    /**
     * <p>
     * A static message in case database resource is not loaded.
     * <p>
     */
    public static final String ERROR_DATABASE_NOT_LOADED =
            "ERROR:  User database not loaded -- check servlet container logs for error messages.";

    /**
     * <P>
     * A "magic" username to trigger an ExpiredPasswordException for testing.
     *</p>
     */
    public static final String EXPIRED_PASSWORD_EXCEPTION = "ExpiredPasswordException";

    /**
     * <p>
     * Name of field to associate with authentification errors.
     * <p>
     */
    public static final String PASSWORD_MISMATCH_FIELD = "password";

    // ---- Log Messages ----

    /**
     * <p> Message to log if saving a user fails. </p>
     */
    public static final String LOG_DATABASE_SAVE_ERROR =
            " Unexpected error when saving User: ";
    
    
    public static final String SYS_CONFIG_FILE_NAME =
        "config.properites";
    
    public static String getSysShowDate(){
    	return getConfigValue("format.date.sysShow");
    }
    
    public static String getSysShowTime(){
    	return getConfigValue("format.time.sysShow");
    }
    
    public static String getSANODate(){
    	return getConfigValue("format.date.sano");
    }
    
    public static String getSANOFormat(){
    	return getConfigValue("format.sano");
    }
    
    public static String getConfigValue(String key)  {
		try {
			Configuration config = new PropertiesConfiguration(SYS_CONFIG_FILE_NAME);
			return config.getString(key);
		} catch (ConfigurationException e) {
			throw new RuntimeException("System Config was wrong!");
		}
    }
    
    
    public static final int STATUS_SA_NONE = 0;
    public static final int STATUS_SA_NEEDHAND = 1;
    public static final int STATUS_SA_HANDED = 2;
    
    public static final int STATUS_ENABLE = 1;
    public static final int STATUS_DISABLE = 0;
    
    public static final String SATYPE_ALL = "all";
    public static final String SATYPE_OCEAN = "ocean";
    public static final String SATYPE_AIR = "air";
    
    public static final int ROLE_CUSTOMER = 0;
    public static final int ROLE_SYSUSER = 1;
    public static final int ROLE_ADMIN = 2;
    public static Map<Integer,String> USER_ROLES = new LinkedHashMap<Integer,String>();
    static{
    	USER_ROLES.put(ROLE_CUSTOMER, "Customer");
    	USER_ROLES.put(ROLE_SYSUSER, "SysUser");
    	USER_ROLES.put(ROLE_ADMIN, "Admin");
    }
    
	
	public static final int AIRSA_STATUS_RBK = 10;
	public static final int AIRSA_STATUS_OWW = 20;
	public static final int AIRSA_STATUS_RCF = 30;
	public static final int AIRSA_STATUS_RCD = 40;
	public static final int AIRSA_STATUS_SAH = 50;
	public static final int AIRSA_STATUS_RFC = 60;
	public static final int AIRSA_STATUS_DEP = 70;
	public static final int AIRSA_STATUS_DLV = 71;
	public static final int AIRSA_STATUS_ARR = 80;
	public static final int AIRSA_STATUS_NFD = 90;
	public static final int AIRSA_STATUS_DEL = 100;
	public static Map<Integer,String> AIRSA_STATES = new LinkedHashMap<Integer,String>();
	static{
		AIRSA_STATES.put(AIRSA_STATUS_RBK, "RBK");
		AIRSA_STATES.put(AIRSA_STATUS_OWW, "OWW");
		AIRSA_STATES.put(AIRSA_STATUS_RCF, "RCF");
		AIRSA_STATES.put(AIRSA_STATUS_RCD, "RCD");
		AIRSA_STATES.put(AIRSA_STATUS_SAH, "SAH");
		AIRSA_STATES.put(AIRSA_STATUS_RFC, "RFC");
		AIRSA_STATES.put(AIRSA_STATUS_DEP, "DEP");
		AIRSA_STATES.put(AIRSA_STATUS_DLV, "TRT");
		AIRSA_STATES.put(AIRSA_STATUS_ARR, "ARR");
		AIRSA_STATES.put(AIRSA_STATUS_NFD, "NFD");
		AIRSA_STATES.put(AIRSA_STATUS_DEL, "DEL");
	}
	
	
	public static final int OCEANSA_STATUS_RBK = 10;
	public static final int OCEANSA_STATUS_OWW = 20;
	public static final int OCEANSA_STATUS_RCF = 30;
	public static final int OCEANSA_STATUS_RCD = 40;
	public static final int OCEANSA_STATUS_SAH = 50;
	public static final int OCEANSA_STATUS_STP = 60;
	public static final int OCEANSA_STATUS_WSR = 70;
	public static final int OCEANSA_STATUS_SMP = 80;
	public static final int OCEANSA_STATUS_SAL = 90;
	public static final int OCEANSA_STATUS_DDV = 100;
	public static final int OCEANSA_STATUS_ARR = 110;
	public static final int OCEANSA_STATUS_NFD = 120;
	public static final int OCEANSA_STATUS_DLV = 130;
	
	public static Map<Integer,String> OCEANSA_STATES = new LinkedHashMap<Integer,String>();
	static{
		OCEANSA_STATES.put(OCEANSA_STATUS_RBK, "RBK");
		OCEANSA_STATES.put(OCEANSA_STATUS_OWW, "OWW");
		OCEANSA_STATES.put(OCEANSA_STATUS_RCF, "RCF");
		OCEANSA_STATES.put(OCEANSA_STATUS_RCD, "RCD");
		OCEANSA_STATES.put(OCEANSA_STATUS_SAH, "SAH");
		OCEANSA_STATES.put(OCEANSA_STATUS_STP, "STP");
		OCEANSA_STATES.put(OCEANSA_STATUS_WSR, "WSR");
		OCEANSA_STATES.put(OCEANSA_STATUS_SMP, "SMP");
		OCEANSA_STATES.put(OCEANSA_STATUS_SAL, "SAL");
		OCEANSA_STATES.put(OCEANSA_STATUS_DDV, "DDV");
		OCEANSA_STATES.put(OCEANSA_STATUS_ARR, "ARR");
		OCEANSA_STATES.put(OCEANSA_STATUS_NFD, "NFD");
		OCEANSA_STATES.put(OCEANSA_STATUS_DLV, "DLV");
	}
	
	public static final int USERTIP_MAWBSHIPPER = 1;
	public static final int USERTIP_MAWBCONSIGNEE = 2;
	public static final int USERTIP_HAWBSHIPPER = 3;
	public static final int USERTIP_HAWBCONSIGNEE = 4;
	public static final Map<Integer,String> USERTIP_TYPES = new LinkedHashMap<Integer,String>();
	static{
		USERTIP_TYPES.put(USERTIP_MAWBSHIPPER, "MAWB Shipper");
		USERTIP_TYPES.put(USERTIP_MAWBCONSIGNEE, "MAWB Consignee");
		USERTIP_TYPES.put(USERTIP_HAWBSHIPPER, "HAWB Shipper");
		USERTIP_TYPES.put(USERTIP_HAWBCONSIGNEE, "HAWB Consignee");
	}
	
	
	public static String CONFIG_ATTACH_FOLDER = "";
	
	public static final int ATTACHMENT_SHOWTYPE_SYS = 1;
}
